package com.example.demo.controller;

import com.example.demo.model.activiti.Task;
import com.example.demo.service.IFirstDemoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("firstDemo")
public class FirstDemoControl {
    @Autowired
    private IFirstDemoService firstDemoService;

    //开启流程实例
    @ApiOperation(value = "开启流程实例",notes = "")
    @RequestMapping(value = "/process/{personId}/{compId}", method = RequestMethod.GET)
    public void startProcessInstance(@PathVariable Long personId, @PathVariable Long compId) {
        firstDemoService.startProcess(personId, compId);
    }

    //获取当前人的任务
    @ApiOperation(value = "获取当前人的任务",notes = "")
    @RequestMapping(value = "/tasks", method = RequestMethod.GET)
    public List<Task> getTasks(@RequestParam String assignee) {
        List<org.activiti.engine.task.Task> tasks = firstDemoService.getTasks(assignee);
        List<Task> dtos = new ArrayList<Task>();
        for (org.activiti.engine.task.Task task : tasks) {
            dtos.add(Task.createTaskInformaticFromActiviti(task));
        }
        return dtos;
    }

    //完成任务
    @ApiOperation(value = "完成任务",notes = "")
    @RequestMapping(value = "/complete/{joinApproved}/{taskId}", method = RequestMethod.GET)
    public String complete(@PathVariable Boolean joinApproved, @PathVariable String taskId) {
        firstDemoService.completeTasks(joinApproved, taskId);
        return "ok";
    }
}
